package com.xiyu.service.controller.admin.material;
import com.xiyu.service.vo.material.stockIn.StockInSingleGetOutput;
import com.xiyu.service.vo.material.stockIn.StockInUpdateStatusInput;
import com.xiyu.service.vo.material.stockIn.StockInUpdateInput;
import com.xiyu.service.vo.material.stockIn.StockInCreateInput;
import com.xiyu.service.vo.material.stockIn.StockInPageQueryOutput;
import com.xiyu.service.vo.material.stockIn.StockInPageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.material.StockInService;

@Tag(name = "入库管理")
@RestController
@RequestMapping("/material/stock-in")
@Validated
public class StockInController {

    @Resource
    private StockInService stockInService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询入库单")
    @PreAuthorize("@ss.hasPermission('material:stockIn:query')")
    public CommonResult<PageResult<StockInPageQueryOutput>> pageQuery(@Valid StockInPageQueryInput inputVO) {
        return success(stockInService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增入库单")
    @PreAuthorize("@ss.hasPermission('material:stockIn:create')")
    public CommonResult<Long> create(@Valid @RequestBody StockInCreateInput inputVO) {
        return success(stockInService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新入库单")
    @PreAuthorize("@ss.hasPermission('material:stockIn:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody StockInUpdateInput inputVO) {
        return success(stockInService.update(inputVO));
    }

    @PutMapping("/update-status")
    @Operation(summary = "更新入库单状态")
    public CommonResult<Boolean> updateStatus(@Valid @RequestBody StockInUpdateStatusInput inputVO) {
        return success(stockInService.updateStatus(inputVO));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个入库单")
    @Parameter(name = "id", description = "物资入库单主键ID", example = "")
    public CommonResult<StockInSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(stockInService.singleGet(id));
    }

}
